<template>
  <div>
    <menu-nav></menu-nav>
    <div class="box">
      <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
        <van-card
          @click="toGoodsDetail(item.goods_id)"
          v-for="item in goodList.goods"
          :key="item.goods_id"
          :num="item.goods_number"
          :price="item.goods_price"
          :title="item.goods_name"
          :thumb="item.goods_small_logo"
        />
      </van-pull-refresh>
    </div>
  </div>
</template>
<script>
import Navgation from '../util/header.vue'
import Vue from 'vue'
export default {
  props: ['id', 'name'],
  data() {
    return {
      queryInfo: {
        query: '',
        cid: '',
        pagenum: 1,
        pagesize: 10
      },
      goodList: [],
      count: 0,
      isLoading: false
    }
  },
  created() {
     this.getgoodlist()
  },
  components: {
    'menu-nav': Navgation
  },
  methods: {
    async getgoodlist() {
      if (this.id) {
         this.queryInfo.cid = this.id  
      }else if(this.name){
        this.queryInfo.query=this.name     
      }
      //发送请求
        const data = await this.$axios.get('/goods/search', {
          params: this.queryInfo
        })
        console.log(data)
        if (data.meta.status !== 200) {
          this.$notify(data.meta.msg)
        } else {
          this.goodList = data.message
        }
    },
    toGoodsDetail(id) {
      this.$router.push('/goodlist/' + id)
    },
    onRefresh() {
      setTimeout(() => {
        this.$toast('刷新成功')
        this.isLoading = false
        this.count++
      }, 1000)
    }
  }
}
</script>
<style lang="less" scoped>
.title {
  background-color: #c73420;
  height: 1rem;
  .title_hm {
    line-height: 1rem;
    text-align: center;
    color: #ffffff;
    font-family: '微软雅黑';
    font-size: 0.5rem;
  }
}
.box {
  margin-top: 50px;
}
</style>